<script lang="ts" setup>
import { orderStatus } from "@/contants/classification";
import { Formattime } from "@/logics/geshiitem";
import { useHomeStore } from "@/stores/homeStore";
import { ref } from "vue";
//引入路由
const router = useRouter();

const page = ref(1);
//获取首页的store实例
const homeStore = useHomeStore();
const { homeActives } = storeToRefs(homeStore);
//获取首页文章数据
const { getActives } = homeStore;
getActives(page.value);
const load = () => {
  //每次触底页码加一
  page.value = page.value + 1;
  //获取下一页数据
  getActives(page.value);
};
//跳转文章详情
function Goto(nid: number) {
  router.push({
    path: `/article/${nid}`,
  });
}
</script>
<template>
  <div class="main">
    <ul v-infinite-scroll="load" class="infinite-list" style="overflow: auto">
      <li   @click="Goto(item.nid)"
        v-for="item in homeActives.result.data"
        class="infinite-item"
        :key="item.nid"
      >
        <div class="back-img">
          <img :src="item.cover" alt="" />
          <div class="abstract">{{ item.abstract }}</div>
          <div class="tag">{{ orderStatus[item.category] }}</div>
          <div class="tetle">{{ item.title }}</div>
        </div>
        <div class="lifoot">
          <div class="left">
            <ul>
              <li>
                <i class="fa fa-calendar" aria-hidden="true"></i>
                {{ Formattime(item.create_date) }}
              </li>
              <li>
                <i class="fa fa-star-half-o" aria-hidden="true"></i
                >{{ item.digg_count }}人点赞
              </li>
              <li>
                <i class="fa fa-commenting-o" aria-hidden="true"></i>
                {{ item.comment_count }}条评论
              </li>
              <li>
                <i class="fa fa-star-half-o" aria-hidden="true"></i
                >{{ item.collects_count }}人收藏
              </li>
            </ul>
          </div>
          <div class="right"></div>
        </div>
      </li>
      <div class="loading" v-if="homeActives.status === 'loading'">
        <span class="img"></span>
        <span class="text">正在加载...</span>
      </div>
      <div class="finished" v-if="homeActives.status === 'finished'">
        <span class="img"></span>
        <span class="text">亲，没有更多了</span>
      </div>
    </ul>
  </div>
</template>

<style scoped lang="scss">
.main {
  width: 50%;
  margin: 0 auto;
  overflow: hidden;
  .infinite-list {
    margin-top: 10px;
    width: 110%;
    height: 920px;
    margin: 0 auto;

    .infinite-item {
      width: 90%;
      margin-left: 1.5%;
      height: 300px;
      background: var(--el-bg-color);
      color: var(--el-color-primary);
      margin-top: 20px;
      border-radius: 10px;
      cursor: pointer;
      .back-img:hover {
        box-shadow: 0 0 15px -5px #000;
      }
      .back-img {
        width: 100%;
        height: 260px;
        position: relative;
        overflow: hidden;
        border-radius: 10px 10px 0 0;
        .abstract {
          color: white;
          font-size: 23px;
          background-color: rgba(0, 0, 0, 0.3);
          text-align: center;
          width: 100%;
          height: 61%;
          padding: 18% 0 0 0;
          position: absolute;
          left: 0;
          top: -125%;
          z-index: 2;
          border-radius: 10px;
          transition: all 0.3s ease 0s;
        }

        img {
          border-radius: 10px 10px 0 0;
          width: 100%;
          height: auto;
          transition: all 0.3s ease 0s;
        }

        .tag {
          padding-left: 10px;
          padding-right: 10px;
          position: absolute;
          top: 40%;
          left: calc(50% - 25px);
          height: 20px;
          background-color: #ff2e63;
          color: var(--el-bg-color);
          border-radius: 5px;
          font-size: 14px;
          text-align: center;
          line-height: 20px;
          transition: all 0.3s ease 0s;
        }
        .tetle {
          width: 500px;
          position: absolute;
          top: 50%;
          text-align: center;
          left: calc(50% - 250px);
          margin-top: 20px;
          color: var(--el-bg-color);
          font-size: 30px;
          text-shadow: 1px 1px 1px var(--el-color-info-light-3);
          transition: all 0.3s ease 0s;
        }
      }
      .back-img:hover .tag {
        top: -10%;
      }
      .back-img:hover .tetle {
        top: 110%;
      }
      .back-img:hover .abstract {
        top: 0;
      }
      .lifoot {
        margin-top: 10px;
        .left {
          margin-left: 10px;
          color: var(--el-color-info);
          ul {
            display: flex;
            font-size: 14px;
            li {
              margin-left: 10px;
              i {
                margin-right: 5px;
              }
            }
          }
        }
      }
    }
    .loading {
      display: flex;
      flex-direction: column;
      align-items: center;
      justify-content: center;
      height: 200px;
      .img {
        width: 200px;
        height: 200px;

        background: url(@/assets/img/login.gif) no-repeat center / contain;
      }
      .text {
        display: block;
        color: #999;
        font-size: 16px;
      }
    }
    .finished {
      display: flex;
      flex-direction: column;
      align-items: center;
      justify-content: center;
      height: 200px;
      .img {
        width: 200px;
        height: 200px;
        background: url(@/assets/img/Moreno.gif) no-repeat center / contain;
      }
      .text {
        display: block;
        color: #999;
        font-size: 16px;
      }
    }
  }
}
</style>
